
import 'dart:math';

import 'package:flutter/material.dart';

void main() =>runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context){
    return MaterialApp(
        home:sliverDemo01()
    );
  }
}

class sliverDemo01 extends StatelessWidget {
  const sliverDemo01({
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    return HYHomePage();
  }
}

class HYHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context){
    return Scaffold(
      // appBar: AppBar(
      //   title: Text("列表测试"),
      // ),
      body:CustomScrollView(
        slivers: [
          SliverAppBar(
            expandedHeight: 300,
            pinned: true,
            flexibleSpace: FlexibleSpaceBar(
              title: Text('Hello World'),
              background: Image.asset('assets/images/pic.png',fit:BoxFit.cover),
            ),
          ),
          SliverGrid(
              delegate: SliverChildBuilderDelegate((ctx,int int){
                return Container(
                    color: Color.fromARGB(255,Random().nextInt(256),Random().nextInt(256),Random().nextInt(256))
                );
              },
                childCount: 10
              ),
              gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                crossAxisCount: 2,
                crossAxisSpacing: 8,
                mainAxisSpacing: 8,
                childAspectRatio: 2
              )
          ),
          SliverList(delegate: SliverChildBuilderDelegate(( ctx,int index){
            return ListTile(
              leading: Icon(Icons.people),
              title: Text('联系人'),
            );
          },
            childCount: 200
          ))
        ],
      )
    );
  }
}

class CustomScrollViewDemo01 extends StatelessWidget {
  const CustomScrollViewDemo01({
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    return CustomScrollView(
      slivers: <Widget>[
        /*
        * SliverSafeArea 头部的安全区
        * **/

        SliverSafeArea(sliver:SliverPadding(
        padding: EdgeInsets.all(8),
        sliver:SliverGrid(
         delegate: SliverChildBuilderDelegate((ctx,int int){
           return Container(
               color: Color.fromARGB(255,Random().nextInt(256),Random().nextInt(256),Random().nextInt(256))
           );
         }),
         gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
             crossAxisCount: 2,
             crossAxisSpacing: 8,
             mainAxisSpacing: 8,
             childAspectRatio: 1.5
         ),))
        )
      ],
    );
  }
}






